fix(test): make issue-2898-comment.js assertion robust against flakiness#5208
Merged
fix(test): make issue-2898-comment.js assertion robust against flakiness#5208
Conversation
Move assertions from the HTTP server request handler callback into the test body using a Promise to capture received headers. This avoids the flakiness of t.plan() with assertions executed in an async server callback, where the plan count could mismatch if fetch fails before the request reaches the server. Refs: #5189
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #5208 +/- ##
=======================================
Coverage 93.27% 93.27%
=======================================
Files 110 110
Lines 36349 36349
=======================================
Hits 33904 33904
Misses 2445 2445 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
trivikr
approved these changes
May 5, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #5189.
Problem
test/fetch/issue-2898-comment.jswas flaky. The test usedt.plan(2)with assertions placed inside the HTTP server's request handler callback. When the server callback didn't fire (e.g. iffetchfailed before the request reached the server), the assertions were never run, causing a plan count mismatch and a generic'test failed'failure.Fix
Move the assertions out of the server request handler and into the test body. The server now resolves a
Promisewith the received headers, and the test asserts against them after thefetch()call completes. This ensures assertions always run in the test's execution context regardless of how the server behaves.